package com.daervin.svc.parser.hot;

import com.daervin.svc.dal.model.Resume;
import com.daervin.svc.parser.RootParser;
import org.apache.log4j.Logger;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.selector.Html;
import us.codecraft.webmagic.selector.Selectable;

/**
 * @packageName: com.daervin.svc.parser.hot
 * @CLassName: WuYiJobParSer
 * @Description:
 * @Author: wanxiong.deng
 * @Date: 2021/4/25 19:21
 */
public class WuYiJobParSer extends RootParser {
    private final static Logger LOGGER = Logger.getLogger(WuYiJobParSer.class);

    public WuYiJobParSer(String... parentUrls){
        super(parentUrls);
    }

    @Override
    protected void listProcess(Page page) {
        //对page进行解析成对象然后把对象放进page中
        Html html = page.getHtml();
        if(html == null){
            return;
        }
        Resume resume = new Resume();
        Selectable nameSelectable = html.xpath("//div[@class=\"face\"]//div[@class=\"face\"]//div[@class=\"name\"]/text()");
        Selectable decSelectable = html.xpath("//div[@class=\"face\"]//div[@class=\"face\"]//p[@class=\"at\"]/text()");
        String name = nameSelectable.get();
        String desc = decSelectable.get();
        resume.setName(name);
        resume.setDesc(desc);
        //放进map中，等到下一步的pipeline去取
        page.putField("resume", resume);
    }

    @Override
    public Site getSite() {
        return super.getSite();
    }
}
